﻿/**
 *	(C) 2014 Yuanjj
 *
 *	define net class
 *
 *	histroy
 * 		2014-08-06	Yuanjj		-	create
 */

#include <errno.h>
#include "net.h"
#include "errorcode.h"
#include "routine/global.h"
#include "routine/option/opt.h"

cls_net::cls_net()
{
    _INIT_LOCK( &m_lock );
}

cls_net::~cls_net()
{
    _DEL_LOCK( &m_lock );
}

/**
 *	initialize the data base object
 */
pem_error_t cls_net::instance()
{
    pem_error_t		res = PEM_OK;
    QString			shlib;
    opt_info		opt;

    g_opt.get_opt( opt );

    shlib.sprintf( "%s/sharelib/%s", opt.g_path, opt.net_shlib );

    _LOCK( &m_lock );

    res = _load_net_share_library( shlib );

    _UNLOCK( &m_lock );

    if ( 0 != res )
        g_log.write( LOG_ERR, "net", "net work module initialize failed[error = 0x%x]", res );

    res 	= PEM_OK;
    return	res;
}

/**
 *	release the net object
 */
pem_void_t cls_net::release()
{
    _LOCK( &m_lock );

    m_lib.unload();
    // clear interface
    // ......

    _UNLOCK( &m_lock );
}

/**
 *	load share library for net
 *
 * 	@path		[in] the share library path
 *
 * 	return
 * 		==	0	successful
 * 		!=	0	errorcode
 */
pem_error_t cls_net::_load_net_share_library( QString& path )
{
    pem_error_t			res = 0;

    m_lib.setFileName( path );
    if ( !m_lib.load() )
        return BUILD_ERRORCODE( errno, PEM_NET_LOAD );

    // loading interface
    // ......

    return res;
}
